package com.qyhl.webtv.module_user.shop.item;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.qyhl.webtv.commonlib.entity.user.ShoppingOrderBean;
import com.qyhl.webtv.module_user.R;
import com.zhy.adapter.recyclerview.base.ItemViewDelegate;
import com.zhy.adapter.recyclerview.base.ViewHolder;

public class ItemShopOrderOne implements ItemViewDelegate<ShoppingOrderBean> {
    private Context mContext;

    public ItemShopOrderOne(Context context) {
        this.mContext = context;
    }

    @Override
    public int getItemViewLayoutId() {
        return R.layout.login_item_shop_order_one;
    }

    @Override
    public boolean isForViewType(ShoppingOrderBean item, int position) {
        return item.getItem().getItemType() == 0;
    }

    @Override
    public void convert(ViewHolder holder, ShoppingOrderBean bean, int position) {
        holder.setText(R.id.title, bean.getItem().getItemName());

        holder.setText(R.id.score, bean.getItemPrice());

        holder.setText(R.id.number, "X" + bean.getItemNumber());

        ImageView cover = holder.getView(R.id.cover);
        Glide.with(mContext)
                .load(bean.getItem().getItemPic())
                .apply(new RequestOptions().placeholder(R.drawable.cover_normal_default).error(R.drawable.cover_normal_default))
                .into(cover);

        holder.setText(R.id.date, "兑换时间：" + bean.getCreateTime());

        if (bean.getOrderStatus().equals("DELIVERED")) {
            holder.setVisible(R.id.transport, true);
            holder.setVisible(R.id.order_id, true);

            holder.setText(R.id.transport, "承运商：" + (bean.getCarrier() == null ? "暂无" : bean.getCarrier().getCarrierName()));

            holder.setText(R.id.order_id, "运单号：" + (bean.getCarrier() == null ? "暂无" : bean.getCarrier().getCarrierNumber()));

            holder.setText(R.id.status, "您的订单已发货");
            holder.setBackgroundRes(R.id.status, R.drawable.login_shop_order_status_on_bg);
            holder.setTextColorRes(R.id.status, R.color.shop_base_color);
        } else {
            holder.setVisible(R.id.transport, false);
            holder.setVisible(R.id.order_id, false);

            holder.setText(R.id.status, "您的订单尚未发货");
            holder.setBackgroundRes(R.id.status, R.drawable.login_shop_order_status_off_bg);
            holder.setTextColorRes(R.id.status, R.color.global_base);
        }
    }
}
